package com.ego.receive;

import com.ego.dubbo.service.ItemCatDubboService;
import com.ego.dubbo.service.ItemDubboService;
import com.ego.pojo.Item;
import com.ego.pojo.ItemCat;
import com.ego.pojo.ItemDesc;
import com.ego.pojo.SearchPojo;
import com.ego.utils.HttpClientUtil;
import com.ego.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Component
public class ItemReceiveListener {

    @DubboReference
    private ItemCatDubboService itemCatDubboService;

    @DubboReference
    private ItemDubboService itemDubboService;

    @Autowired
    private SolrTemplate solrTemplate;

    @Value("${ego.solr.core.name}")
    private String collection;

    @RabbitListener(queues = "${ego.rabbitmq.queue.item-insert}")
    public void itemInsertReceive(SearchPojo searchPojo) {
        //将searchPojo中的itemCatName从数据库中查出
        HttpClientUtil.doPostJson("http://localhost:8083/itemInsert", JsonUtils.objectToJson(searchPojo));

    }


    @RabbitListener(queues = "${ego.rabbitmq.queue.item-delete}")
    public void itemDeleteReceive(String[] ids) {
        HttpClientUtil.doGet("http://localhost:8083/itemDelete?ids" + StringUtils.join(ids,","));
    }

    @RabbitListener(queues = "${ego.rabbitmq.queue.item-reshelf}")
    public void itemReshelfReceive(Long[] ids) {
        HttpClientUtil.doGet("http://localhost:8083/itemDelete?ids" + Arrays.toString(ids));
    }

}
